package cn.android.x.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import java.util.ArrayList;
import java.util.List;

public class PhoneUtil {

    public static ArrayList<String> hasInstalled(Context context, String[] packageNameArr) {

        final PackageManager packageManager = context.getPackageManager();//获取packagemanager
        List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);//获取所有已安装程bai序的du包信息
        List<String> pName = new ArrayList<String>();//用于存储所有已安装程序的包名
        //从pinfo中将包名字逐一取出，压入pName list中
        for (int i = 0; i < pinfo.size(); i++) {
            String pn = pinfo.get(i).packageName;
            pName.add(pn);
        }

        ArrayList<String> hasAppPnList = new ArrayList<>();

        for (String markPN : packageNameArr) {
            if (pName.contains(markPN)) {
                hasAppPnList.add(markPN);
            }
        }
        return hasAppPnList;//判断pName中是否有目标程序的包名，有TRUE，没有FALSE
    }
}
